<?php
namespace BP\Sys;

use BP\En\EntityMyPK;

require_once("BP/En/Map.php");
require_once("BP/Web/WebUser.php");
class SysEnum extends EntityMyPK {
	public static function GetLabByPK ($EnumKey, $intKey) // [String EnumKey, int intKey]
	{
		$en = SysEnum::constructor__String_I($EnumKey, $intKey);
		return $en->getLab();
	}
	public function getLab () 
	{
		return $this->GetValStringByKey(SysEnumAttr::$Lab);
	}
	public function setLab ($value) // [String value]
	{
		$this->SetValByKey(SysEnumAttr::$Lab, $value);
	}
	public function getLang () 
	{
		return $this->GetValStringByKey(SysEnumAttr::$Lang);
	}
	public function setLang ($value) // [String value]
	{
		$this->SetValByKey(SysEnumAttr::$Lang, $value);
	}
	public function getIntKey () 
	{
		return $this->GetValIntByKey(SysEnumAttr::$IntKey);
	}
	public function setIntKey ($value) // [int value]
	{
		$this->SetValByKey(SysEnumAttr::$IntKey, $value);
	}
	public function getEnumKey () 
	{
		return $this->GetValStringByKey(SysEnumAttr::$EnumKey);
	}
	public function setEnumKey ($value) // [String value]
	{
		$this->SetValByKey(SysEnumAttr::$EnumKey, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String_I ($enumKey, $val) // [String enumKey, int val]
	{
		$me = new self();
		$me->setEnumKey($enumKey);
		$me->setLang($WebUser->getSysLang());
		$me->setIntKey($val);
		$me->setMyPK((((($me->getEnumKey() . "_") . $me->getLang()) . "_") . $me->getIntKey()));
		$i = $me->RetrieveFromDBSources();
		if (($i == 0))
		{
			$i = $me->Retrieve(SysEnumAttr::$EnumKey, $enumKey, SysEnumAttr::$Lang, $WebUser->getSysLang(), SysEnumAttr::$IntKey, $me->getIntKey());
			$ses = SysEnums::constructor__();
			$ses->Full($enumKey);
			if (($i == 0))
			{
				$myee = SysEnums::constructor__String($enumKey);
				throw new \RuntimeException((((((("@ EnumKey=" . $me->getEnumKey()) . " Val=") . $val) . " Lang=") . $WebUser->getSysLang()) . " ...Error"));
			}
		}
		return $me;
	}
	public static function constructor__String_String_I ($enumKey, $Lang, $val) // [String enumKey, String Lang, int val]
	{
		$me = new self();
		$me->setEnumKey($enumKey);
		$me->setLang($Lang);
		$me->setIntKey($val);
		$me->setMyPK((((($me->getEnumKey() . "_") . $me->getLang()) . "_") . $me->getIntKey()));
		$i = $me->RetrieveFromDBSources();
		if (($i == 0))
		{
			$i = $me->Retrieve(SysEnumAttr::$EnumKey, $enumKey, SysEnumAttr::$Lang, $Lang, SysEnumAttr::$IntKey, $me->getIntKey());
			$ses = SysEnums::constructor__();
			$ses->Full($enumKey);
			if (($i == 0))
			{
				throw new \RuntimeException((((((("@ EnumKey=" . $enumKey) . " Val=") . $val) . " Lang=") . $Lang) . " Error"));
			}
		}
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("Sys_Enum", "枚举数据");
		$map->Java_SetDepositaryOfEntity($Depositary->None);
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->Java_SetEnType($EnType->Sys);
		$map->AddMyPK();
		$map->AddTBString(SysEnumAttr::$Lab, NULL, "Lab",  TRUE ,  FALSE , 1, 300, 8);
		$map->AddTBString(SysEnumAttr::$EnumKey, NULL, "EnumKey",  TRUE ,  FALSE , 1, 100, 8);
		$map->AddTBInt(SysEnumAttr::$IntKey, 0, "Val",  TRUE ,  FALSE );
		$map->AddTBString(SysEnumAttr::$Lang, "CH", "语言",  TRUE ,  FALSE , 0, 10, 8);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	protected function beforeUpdateInsertAction () 
	{
		if ((($this->getLang() . NULL) . $this->getLang()->equals("")))
		{
			$this->setLang($WebUser->getSysLang());
		}
		$this->setMyPK((((($this->getEnumKey() . "_") . $this->getLang()) . "_") . $this->getIntKey()));
		return parent->beforeUpdateInsertAction();
	}
	protected function afterInsert () 
	{
		$sql = ((" select  distinct(FK_MapData)from Sys_FrmRB where EnumKey='" . $this->getEnumKey()) . "'");
		$dt = DBAccess->RunSQLReturnTable($sql);
		if (($dt->Rows->size() == 0))
		{
			parent->afterInsert();
			return ;
		}
		foreach ($dt->Rows as $dr) 		{
			if ($DataType->IsNullOrEmpty($dr->getValue(0)))
			{
				continue;
			}
			$fk_mapdata = $dr->getValue(0);
			$mypk = (((($fk_mapdata . "_") . $this->getEnumKey()) . "_") . $this->getIntKey());
			$frmrb = FrmRB::constructor__();
			if (($frmrb->IsExit("MyPK", $mypk) ==  TRUE ))
			{
				$frmrb->setLab($this->getLab());
				$frmrb->Update();
				continue;
			}
			$mapAttr = MapAttr::constructor__String((($fk_mapdata . "_") . $this->getEnumKey()));
			$RBShowModel = $mapAttr->GetParaInt("RBShowModel");
			$frmrb1 = FrmRB::constructor__String(((($fk_mapdata . "_") . $this->getEnumKey()) . "_0"));
			$frmrb->setFK_MapData($fk_mapdata);
			$frmrb->setKeyOfEn($this->getEnumKey());
			$frmrb->setEnumKey($this->getEnumKey());
			$frmrb->setLab($this->getLab());
			$frmrb->setIntKey($this->getIntKey());
			if (($RBShowModel == 0))
			{
				$frmrb->setX($frmrb1->getX());
				$frmrb->setY(($frmrb1->getY() + 40));
			}
			if (($RBShowModel == 3))
			{
				$frmrb->setX(($frmrb1->getX() + 100));
				$frmrb->setY($frmrb1->getY());
			}
			$frmrb->Insert();
		}
		parent->afterInsert();
	}
}
?>
